<template>
    <!-- 歌曲列表组件 -->
    <div class="list">
        <div
            class="item "
            v-for="(item, index) of songList"
            :key="item.id"
        >
            <!-- 卡片 -->
            <el-card class="box-card">
                <div
                    class="container "
                    :class="index == currentIndex && currentSong.id == item.id && playing ? 'playing': ''"
                >
                    <div class="index-container flex-center ">
                        <!-- 序号 -->
                        <span class="num">{{ utils.formatZero(index + 1, 2) }}</span>
                        <!-- 歌曲播放中的图标 -->
                        <div class="play-icon">
                            <div
                                class="line"
                                style="animation-delay: -1.2s;"
                            ></div>
                            <div class="line"></div>
                            <div
                                class="line"
                                style="animation-delay: -1.5s;"
                            ></div>
                            <div
                                class="line"
                                style="animation-delay: -0.9s;"
                            ></div>
                            <div
                                class="line"
                                style="animation-delay: -0.6s;"
                            ></div>
                        </div>
                        <!-- 播放图标 -->
                        <i
                            class="iconfont nicebofang2 play-btn"
                            @click="playSong(item, index)"
                        ></i>
                        <!-- 暂停图标 -->
                        <i
                            class="iconfont nicezanting1 pause-btn"
                            @click="pauseSong(item, index)"
                        ></i>
                    </div>
                    <!-- 歌曲封面 -->
                    <div class="avatar">
                        <el-image
                            :key="item.image + '?param=150y150'"
                            :src="item.image + '?param=150y150'"
                            lazy
                        >
                        </el-image>
                    </div>
                    <!-- 歌曲信息 -->
                    <div class="info ellipsis">
                        <p class="name ">{{ item.name }}</p>
                        <p class="singer flex-row ellipsis">
                            <span>{{ item.singer }}</span>
                        </p>
                    </div>
                    <!-- 歌曲专辑 -->
                    <p class="album">《{{ item.album }}》</p>
                    <!-- 歌曲时长 -->
                    <p class="duration transition">
                        {{ utils.formatSecondTime(item.duration) }}
                    </p>
                </div>
            </el-card>
        </div>
    </div>
</template>

<script>
import { mapGetters, mapActions } from 'vuex'

export default {
    data() {
        return {

        }
    },
    props: {
        songList: {
            type: Array
        }
    },
    created() {
    },
    computed: {
        ...mapGetters(['currentIndex', 'playing', 'currentSong',]),
    },
    methods: {
        // 播放歌曲
        playSong(item, index) {
            this.selectPlay({
                list: this.songList,
                index
            })
        },
        // 停止播放歌曲
        pauseSong() {
            this.pausePlay()
        },
        ...mapActions([
            // 点击选择播放
            'selectPlay',
            // 点击播放全部
            'playAll',
            'pausePlay'
        ])
    },
}
</script>

<style lang="less" scoped>
.list {
    display: flex;
    flex-flow: wrap;
    margin: 20px -15px;
    .item {
        flex: 0 0 50%;
        max-width: 50%;
        padding: 0 15px 20px;
        .box-card {
            width: 100%;
            height: 80px;
            .container {
                height: 40px;
                display: flex;
                align-items: center;
                .index-container {
                    width: 30px;
                    height: 100%;
                    margin-right: 20px;
                    .num {
                        font-size: 15px;
                        color: #4a4a4a;
                        font-weight: bold;
                    }
                    .play-icon {
                        display: none;
                        height: 16px;
                        min-width: 18px;
                        overflow: hidden;

                        .line {
                            width: 2px;
                            height: 100%;
                            margin-left: 2px;
                            background-color: #ff410f;
                            animation: play 0.9s linear infinite alternate;
                        }
                    }
                    .play-btn,
                    .pause-btn {
                        color: #ff410f;
                        font-size: 30px;
                        display: none;
                        text-align: left;
                        cursor: pointer;
                    }
                }
                &:hover {
                    .index-container {
                        .num {
                            display: none;
                        }
                        .play-btn {
                            display: block;
                        }
                    }
                    &.playing {
                        .index-container {
                            .play-btn {
                                display: none;
                            }

                            .play-icon {
                                display: none;
                            }

                            .pause-btn {
                                display: block;
                            }
                        }
                    }
                }
                &.playing {
                    .index-container {
                        .num {
                            display: none;
                        }
                        .play-icon {
                            display: flex;
                        }
                        .play-btn {
                            display: none;
                        }
                    }
                }
                .avatar {
                    width: 55px;
                    height: 55px;
                    border-radius: 5px;
                    margin-right: 30px;
                    .el-image {
                        border-radius: 5px;
                    }
                }
                .info {
                    width: 15%;
                    .name,
                    .singer {
                        white-space: nowrap;
                        overflow: hidden;
                        text-overflow: ellipsis;
                    }
                    .name {
                        font-size: 14px;
                        color: #333333;
                        font-weight: bold;
                    }
                    .singer {
                        margin-top: 10px;
                        font-size: 12px;
                        color: #666666;
                    }
                }
                .album {
                    font-size: 14px;
                    color: #333333;
                    font-weight: bold;
                    margin-left: 60px;
                    flex: 1;
                    line-height: 20px;
                }
                .duration {
                    font-size: 14px;
                    color: #333333;
                    font-weight: bold;
                }
            }
        }
    }
}
</style>